from import_export import resources
from import_export.fields import Field

from aitest.models import AITestCase, AITestDetail, BuildInfo


class AITestCaseResource(resources.ModelResource):
    user = Field(column_name='user', attribute='user__email')

    def get_queryset(self, **kwargs):
        queryset = AITestCase.objects.all()
        # 根据传入的参数进行过滤
        if 'test_summary' in kwargs:
            queryset = queryset.filter(test_summary__contains=kwargs['test_summary'])
        if 'user' in kwargs:
            queryset = queryset.filter(user__email=kwargs['user'])
        return queryset

    class Meta:
        model = AITestCase

class AITestDetailResource(resources.ModelResource):
    ai_test_case = Field(column_name='ai_test_case', attribute='ai_test_case__id')
    class Meta:
        model = AITestDetail

class BuildInfoResource(resources.ModelResource):
    class Meta:
        model = BuildInfo
